package UDP;

import java.io.IOException;
import java.net.*;

public class UDP_test_Out {
    public static void main(String[] args) throws IOException {
        // 创建UDP套接字
        DatagramSocket d = new DatagramSocket();

        // 准备要发送的数据
        String str = "hello world";
        byte[] b = str.getBytes();
        InetAddress inetAddress = InetAddress.getByName("127.0.0.1");

        int port = 10086;

        // 创建数据报包并发送
        DatagramPacket dp = new DatagramPacket(b, b.length, inetAddress, port);
        d.send(dp);


        System.out.println("数据已发送"+dp.getAddress());
        // 关闭套接字
        d.close();

    }
}
